package com.gljx.web.service.impl;

import com.gljx.web.Entity.SubjectTwoResultentry;
import com.gljx.web.Entity.User;
import com.gljx.web.dao.SubjectTwoResultentryMapper;
import com.gljx.web.service.CustomLogService;
import com.gljx.web.service.SubjectTwoResultentryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SubjectTwoResultentryServiceImpl implements SubjectTwoResultentryService {
	@Autowired
	private SubjectTwoResultentryMapper subjectTwoResultentryMapper;
	@Autowired
	private CustomLogService customLogService;

	@Override
	public List<SubjectTwoResultentry> selSubjectTwoResultentryByParentId(String parentid,String studentName,String cfexmaresult) {
		// TODO Auto-generated method stub
		return subjectTwoResultentryMapper.selSubjectTwoResultentryByParentId(parentid,studentName,cfexmaresult);
	}

	@Override
	public int deleteSubjectTwoResultentryByParentid(String parentid, User user,String fbizdate,String fnumber) {
		// TODO Auto-generated method stub
		if(user !=null){
			List<SubjectTwoResultentry> subjectTwoResultentries =subjectTwoResultentryMapper.selSubjectTwoResultentryByParentId(parentid,null,null);
			for (int i = 0; i < subjectTwoResultentries.size(); i++) {
				//添加学员的服务日志
				customLogService.addLog("考试管理", "删除了学员:"+subjectTwoResultentries.get(i).getCfstufnumber()+subjectTwoResultentries.get(i).getStudentName()
						+",科目二考试结果登记!申请车型:"+subjectTwoResultentries.get(i).getCfsqzjcxdh()+",考试日期:"+fbizdate+"单据编号:"+fnumber, subjectTwoResultentries.get(i).getCfstudentid(), user.getFid());
			}
		}
		return subjectTwoResultentryMapper.deleteByParentId(parentid);
	}

}
